package com.xoa.controller.schedule;

import com.xoa.model.schedule.ResultLeaderActivity;
import com.xoa.model.schedule.Schedule;
import com.xoa.model.schedule.ScheduleModel;
import com.xoa.model.users.Users;
import com.xoa.service.schedule.ScheduleService;
import com.xoa.service.sms.SmsService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * 领导活动安排
 * Created by 程叶同 on 2017-10-07.
 */
@Controller
@RequestMapping("/leaderschedule")
public class ScheduleController {

    @Resource
    private ScheduleService scheduleService;

    @Resource
    private SmsService smsService;


    @RequestMapping("/leaderActivity")
    public String getIndex(HttpServletRequest request){
        ContextHolder.setConsumerType("xoa"
                + (String) request.getSession().getAttribute("loginDateSouse"));

        return "app/leaderActivity/leaderActivity";
    }
    /**
    * @author 程叶同
    * @date 2018/7/25 10:51
    * @desc  页面导航栏
    */
    @RequestMapping("/navigationBar")
    public String navigationBar() {
        return  "app/leaderActivity/navigationBar";
    }
    @RequestMapping("/newLeader")
    public String newLeader() {
        return  "app/leaderActivity/newLeader";
    }
    @RequestMapping("/leaderDetail")
    public String leaderDetail() {
        return  "app/leaderActivity/leaderDetail";
    }
    @RequestMapping("/leaderManager")
    public String leaderManager() {
        return  "app/leaderActivity/leaderManager";
    }

    
    @RequestMapping("/query")
    public String getQuery(HttpServletRequest request){
        ContextHolder.setConsumerType("xoa"
                + (String) request.getSession().getAttribute("loginDateSouse"));


        return "app/leaderActivity/query";
    }

    @ResponseBody
    @RequestMapping(value = "/saveSchedule", produces = {"application/json;charset=UTF-8"})
    public ToJson<ScheduleModel> saveSchedule(HttpServletRequest request,ScheduleModel schedule){

       /* Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        schedule.setCreate_user(user.getUid());*/
        return scheduleService.saveSchedule(request,schedule);
    }

    /**
     * 编辑接口
     * 张丽军
     * @param request
     * @param schedule
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateSchedule", produces = {"application/json;charset=UTF-8"})
    public ToJson<ScheduleModel> updateSchedule(HttpServletRequest request,Schedule schedule){
        return scheduleService.updateSchedule(request,schedule);
    }

    /**
     * 详情接口
     * 张丽军
     * @param request
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectScheduleById", produces = {"application/json;charset=UTF-8"})
    public ToJson<ScheduleModel> selectScheduleById(HttpServletRequest request,Integer id){
        //消除事务提醒
        //String id=request.getParameter("id");
        if(id!=null){
            Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
            Users  users=SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
            smsService.setSmsRead("27","leaderschedule/leaderDetail?id="+id,users);
        }
        return scheduleService.selectScheduleById(request,id);
    }

    /**
     * 删除接口
     * 张丽军
     * @param request
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteScheduleById", produces = {"application/json;charset=UTF-8"})
    public ToJson<ScheduleModel> deleteScheduleById(HttpServletRequest request,Integer id){
        return scheduleService.deleteScheduleById(request,id);
    }

    @ResponseBody
    @RequestMapping(value = "/commitSchedule", produces = {"application/json;charset=UTF-8"})
    public ToJson<ScheduleModel> commitSchedule(int id){
        return scheduleService.commitSchedule(id);
    }


    /**
     * 查询列表
     * 张丽军
     * @param schedule
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryLeaderActiveAll", produces = {"application/json;charset=UTF-8"})
    public ToJson<ResultLeaderActivity> queryLeaderActiveAll(HttpServletRequest request,ScheduleModel schedule,Integer page,Integer pageSize,boolean useFlag,String query){
        return scheduleService.queryLeaderActiveAll(request,schedule,page,pageSize,useFlag,query);
    }

    /**
     * 查询列表(权限，只能查看自己的)
     * 张丽军
     * @param schedule
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryLeaderActiveMe", produces = {"application/json;charset=UTF-8"})
    public ToJson<ResultLeaderActivity> queryLeaderActiveMe(ScheduleModel schedule,HttpServletRequest request){
        return scheduleService.queryLeaderActiveMe(schedule,request);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteByids", produces = {"application/json;charset=UTF-8"})
    public BaseWrapper deleteByids( String ids){
        return scheduleService.deleteByids(ids);
    }
}
